package com.hnxxxy.sysmgr.service.impl;

import com.hnxxxy.common.AjaxRtnEntity.AjaxRtnEntity;
import com.hnxxxy.sysmgr.mapper.TokenMapper;
import com.hnxxxy.sysmgr.pojo.Token;
import com.hnxxxy.sysmgr.service.TokenService;
import com.hnxxxy.sysmgr.vo.TokenVo;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Json
 * @date 2020-26-8:07
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenMapper tokenMapper;



    /**
     * 查询所有权限
     * @param tokenVo
     * @return
     */
    @Override
    public List<Token> queryAllToken(TokenVo tokenVo) {
        List<Token> data = this.tokenMapper.queryAllToken(tokenVo);
        return data;
    }

    /**
     * 添加权限
     * @param tokenVo
     */
    @Override
    public Integer addToken(TokenVo tokenVo) {

        try {
            tokenMapper.insertToken(tokenVo);
            return AjaxRtnEntity.success;
        }catch (Exception e){
            e.printStackTrace();
            return AjaxRtnEntity.error;
        }

    }

    /**
     * 修改权限
     * @param tokenVo
     */
    @Override
    public Integer updateToken(TokenVo tokenVo) {
        try {
            tokenMapper.updateToken(tokenVo);
            return AjaxRtnEntity.success;
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRtnEntity.error;
        }
    }

    /**
     * 删除权限
     * @param id
     */
    @Override
    public Integer deleteToken(Integer id) {
        try {
            tokenMapper.deleteToken(id);

            return AjaxRtnEntity.success;
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRtnEntity.error;
        }
    }

    /**
     * 根据pid查询权限数量
     * @param pid
     * @return
     */
    @Override
    public Integer queryTokenByPid(Integer pid) {
        return this.tokenMapper.queryTokenByPid(pid);
    }

    /**
     * 批量删除权限
     * @param ids
     */
    @Override
    public Integer batchDeletetoken(Integer[] ids) {

        try {
            for (Integer id : ids) {
                deleteToken(id);
            }
            return AjaxRtnEntity.success;
        }catch (Exception e){
            return AjaxRtnEntity.error;
        }
    }

}
